<template>
  <div class="rule-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="search-label">车牌号码：</div>
      <el-input v-model="params.carNumber" clearable placeholder="请输入车牌号码" class="search-main" @clear="getList" />
      <div class="search-label">缴费状态：</div>
      <el-select v-model="params.paymentStatus" style="margin-left: -25px; width: 220px" placeholder="请选择">
        <el-option label="全部" :value="null" />
        <el-option label="待缴费" :value="0" />
        <el-option label="已缴费" :value="1" />
      </el-select>
      <el-button type="primary" style="margin-left: 40px" @click="getList">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table :data="list" style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column label="车牌号码" prop="carNumber" />
        <el-table-column label="收费类型" prop="chargeType" :formatter="fnChargeType"/>
        <el-table-column label="停车总时长" prop="parkingTime" />
        <el-table-column label="缴纳费用（元）" prop="actualCharge" :formatter="fnActualCharge"/>
        <el-table-column label="缴纳状态" prop="paymentStatus" :formatter="fnPaymentStatus" />
        <el-table-column label="缴纳方式" prop="paymentMethod" />
        <el-table-column label="缴纳时间" prop="paymentTime" />
      </el-table>
    </div>
    <div class="page-container">
      <el-pagination
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="params.pageSize"
        :page-sizes="[2, 6, 10, 14, 18]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { getPaymentListAPI } from '@/api/payment'

export default {
  data() {
    return {
      params: {
        page: 1,
        pageSize: 10
      },
      form: {
        carNumber: '',
        chargeType: '',
        parkingTime: '',
        actualCharge: 0,
        paymentStatus: 0,
        paymentMethod: '',
        paymentTime: ''
      },
      list: [],
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList() {
      const res = await getPaymentListAPI(this.params)
      this.list = res.data.rows
      this.total = res.data.total
      console.log(res)
    },
    handleCurrentChange(page) {
      this.params.page = page
      this.getList()
    },
    handleSizeChange(pageSize) {
      this.params.pageSize = pageSize
      this.getList()
    },
    fnPaymentStatus(row) {
      return row.paymentStatus === 1 ? '已缴费' : '未缴费'
      // console.log(row, 999)
    },
    fnChargeType(row) {
      return row.chargeType === 'temp' ? '临时停车' : '月卡'
    },
    fnActualCharge(row) {
      return row.chargeType === 'temp' ? row.actualCharge : '0'
    }
  }
}
</script>

<style lang="scss" scoped>
.rule-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 40px;

  .search-label {
    width: 100px;
  }

  .search-main {
    width: 220px;
    margin-right: 20px;
    margin-left: -25px;
  }
}

.create-container {
  margin: 10px 0px;
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>
